package org.ww.order.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.ww.common.constant.RabbitMqConstant;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: gmall
 * @description:
 * @author: ww
 * @create: 2024-10-30 16:15
 **/
@Configuration
public class MqConfig {

    @Bean
    public Queue orderDelayQueue(){
        //String name, boolean durable, boolean exclusive, boolean autoDelete, Map<String, Object> arguments
        Map<String, Object> arguments = new HashMap<>();
        arguments.put("x-dead-letter-exchange", RabbitMqConstant.ORDER_EVENT_EXCHANGE);
        arguments.put("x-dead-letter-routing-key",RabbitMqConstant.ORDER_RELEASE_ORDER_BINDING);
        arguments.put("x-message-ttl",60000);
        return new Queue(RabbitMqConstant.ORDER_DELAY_QUEUE,true,false,false,arguments);
    }

    @Bean
    public Queue orderReleaseOrderQueue(){
        return new Queue(RabbitMqConstant.ORDER_RELEASE_ORDER_QUEUE,true,false,false);
    }

    @Bean
    public Queue orderSeckillOrderQueue(){
        return new Queue(RabbitMqConstant.ORDER_SECKILL_ORDER_QUEUE,true,false,false);
    }

    @Bean
    public TopicExchange orderEventExchange(){
        //String name, boolean durable, boolean autoDelete, Map<String, Object> arguments
        return new TopicExchange(RabbitMqConstant.ORDER_EVENT_EXCHANGE,true,false);
    }

    @Bean
    public Binding orderCreateOrderBinding(){
        //String destination, Binding.DestinationType destinationType, String exchange, String routingKey, Map<String, Object> arguments
        return new Binding(RabbitMqConstant.ORDER_DELAY_QUEUE,
                Binding.DestinationType.QUEUE,
                RabbitMqConstant.ORDER_EVENT_EXCHANGE,
                RabbitMqConstant.ORDER_CREATE_ORDER_BINDING,
                null);
    }

    @Bean
    public Binding orderReleaseOrderBinding(){
        return new Binding(RabbitMqConstant.ORDER_RELEASE_ORDER_QUEUE,
                Binding.DestinationType.QUEUE,
                RabbitMqConstant.ORDER_EVENT_EXCHANGE,
                RabbitMqConstant.ORDER_RELEASE_ORDER_BINDING,
                null);
    }

    @Bean
    public Binding orderReleaseOtherBinding(){
        return new Binding(RabbitMqConstant.STOCK_RELEASE_STOCK_QUEUE,
                Binding.DestinationType.QUEUE,
                RabbitMqConstant.ORDER_EVENT_EXCHANGE,
                RabbitMqConstant.ORDER_RELEASE_OTHER_BINDING,
                null);
    }

    @Bean
    public Binding orderSeckillOrderBinding(){
        return new Binding(RabbitMqConstant.ORDER_SECKILL_ORDER_QUEUE,
                Binding.DestinationType.QUEUE,
                RabbitMqConstant.ORDER_EVENT_EXCHANGE,
                RabbitMqConstant.ORDER_SECKILL_ORDER_BINDING,
                null);
    }

}
